package com.taotao.service.impl;

import com.taotao.entity.CmsContent;
import com.taotao.dao.CmsContentDao;
import com.taotao.service.CmsContentService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * CMS内容表(CmsContent)表服务实现类
 *
 * @author makejava
 * @since 2022-01-21 16:00:19
 */
@Service("cmsContentService")
public class CmsContentServiceImpl implements CmsContentService {
    @Resource
    private CmsContentDao cmsContentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param contentid 主键
     * @return 实例对象
     */
    @Override
    public CmsContent queryById(String contentid) {
        return this.cmsContentDao.queryById(contentid);
    }

    /**
     * 分页查询
     *
     * @param cmsContent  筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<CmsContent> queryByPage(CmsContent cmsContent, PageRequest pageRequest) {
        long total = this.cmsContentDao.count(cmsContent);
        return new PageImpl<>(this.cmsContentDao.queryAllByLimit(cmsContent, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param cmsContent 实例对象
     * @return 实例对象
     */
    @Override
    public CmsContent insert(CmsContent cmsContent) {
        this.cmsContentDao.insert(cmsContent);
        return cmsContent;
    }

    /**
     * 修改数据
     *
     * @param cmsContent 实例对象
     * @return 实例对象
     */
    @Override
    public CmsContent update(CmsContent cmsContent) {
        this.cmsContentDao.update(cmsContent);
        return this.queryById(cmsContent.getContentid());
    }

    /**
     * 通过主键删除数据
     *
     * @param contentid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String contentid) {
        return this.cmsContentDao.deleteById(contentid) > 0;
    }
}
